<?php
/**
 * 
 * @todo description of this class
 * 
 * @author Alton Crossley <crossleyframework@nogahidebootstrap.com>
 * @package Crossley Framework
 *  
 * @copyright Copyright (c) 2003-2009, Nogaide BootStrap INC. All rights reserved.
 * @license BSD http://opensource.org/licenses/bsd-license.php
 * @version $Id:$
 * 
 */
class X_Data_Meta_Forienkey
{
    /**
     * Forien Key name
     *
     * @var string
     */
    public $sName;
    /**
     * Table Name
     *
     * @var string
     */
    public $sTable;
    /**
     * Column Name
     *
     * @var string
     */
    public $sColumn;
    /**
     * Name of Destination Table
     *
     * @var string
     */
    public $sDestinationTable;
    /**
     * Abbrivated Name of Destination Table
     *
     * @var string
     */
    public $sDestinationAbbr;
    /**
     * Name of Destination Column
     *
     * @var string
     */
    public $sDestinationColumnName;

    /**
     * action to take when target is deleted
     *
     * @var string
     */
    public $sOnDeleteAction = 'No Action';
    /**
     * Action to take when target is updated
     *
     * @var string
     */
    public $sOnUpdateAction = 'No Action';
    
    function __construct($aAttributes = null)
    {
    	if (is_array($aAttributes))
    	{
    		$this->fromArray($aAttributes);
    	}
    }
    
    /**
     * @return string
     */
    public function getColumn()
    {
        return $this->sColumn;
    }
    
    /**
     * @param string $sColumn
     */
    public function setColumn($sColumn)
    {
        $this->sColumn = (string)$sColumn;
    }
    
    /**
     * @return string
     */
    public function getDestinationAbbr()
    {
        return $this->sDestinationAbbr;
    }
    
    /**
     * @param string $sDestinationAbbr
     */
    public function setDestinationAbbr($sDestinationAbbr)
    {
        $this->sDestinationAbbr = (string)$sDestinationAbbr;
    }
    
    /**
     * @return string
     */
    public function getDestinationColumnName()
    {
        return $this->sDestinationColumnName;
    }
    
    /**
     * @param string $sDestinationColumnName
     */
    public function setDestinationColumnName($sDestinationColumnName)
    {
        $this->sDestinationColumnName = (string)$sDestinationColumnName;
    }
    
    /**
     * @return string
     */
    public function getDestinationTable()
    {
        return $this->sDestinationTable;
    }
    
    /**
     * @param string $sDestinationTable
     */
    public function setDestinationTable($sDestinationTable)
    {
        $this->sDestinationTable = (string)$sDestinationTable;
    }
    
    /**
     * @return string
     */
    public function getName()
    {
        return $this->sName;
    }
    
    /**
     * @param string $sName
     */
    public function setName($sName)
    {
        $this->sName = (string)$sName;
    }
    
    /**
     * @return string
     */
    public function getOnDeleteAction()
    {
        return $this->sOnDeleteAction;
    }
    
    /**
     * @param string $sOnDeleteAction
     */
    public function setOnDeleteAction($sOnDeleteAction)
    {
        $this->sOnDeleteAction = (string)$sOnDeleteAction;
    }
    
    /**
     * @return string
     */
    public function getOnUpdateAction()
    {
        return $this->sOnUpdateAction;
    }
    
    /**
     * @param string $sOnUpdateAction
     */
    public function setOnUpdateAction($sOnUpdateAction)
    {
        $this->sOnUpdateAction = (string)$sOnUpdateAction;
    }
    
    /**
     * @return string
     */
    public function getTable()
    {
        return $this->sTable;
    }
    
    /**
     * @param string $Table
     */
    public function setTable($Table)
    {
        $this->sTable = $Table;
    }
    
    /**
     * map array for setting attributes form Array values
     *
     * @var array
     */
    static protected $_aArrayMap = array(
        'name' => 'sName'
        ,'column' => 'sColumn'
        ,'to_table' => 'sDestinationTable'
        ,'to_abbreviated_name' => 'sDestinationAbbr'
        ,'to_column' => 'sDestinationColumnName'
        ,'on_delete' => 'sOnDeleteAction'
        ,'on_update' => 'sOnUpdateAction'
    );
    
    /**
     * factory to build this class from an array
     *
     * @param Array $aArray
     * @return X_Data_Meta_Forienkey
     */
    static public function fromArray(Array $aArray)
    {
        $sClass = __CLASS__;
        $oNew = new $sClass();
        
        foreach ($aArray as $sKey => $sValue)
        {
            if (array_key_exists($sKey, self::$_aArrayMap))
            {
                $sAttrName = self::$_aArrayMap[$sKey];
                $oNew->$sAttrName = $sValue;
            }
            else if (property_exists(__CLASS__, $sKey))
            {
            	$oNew->$sKey = $sValue;
            }
        }
        
        return $oNew;
        
    }

    /**
     * public wrapper for __toArray()
     *
     * @return array
     */
    public function toArray()
    {
        return $this->__toArray();
    }
    
	/**
     * convert the current object to an array
     *
     * @return array
     */
    public function __toArray()
    {
        $a = array();
        foreach (self::$_aArrayMap as $sKey => $sValue)
        {
            $a[$skey] = $this->$sValue;
        }
        
        return $a;
    }
}